import { http } from "@/utils/http";
import baseUrlProxy from "@/api/baseUrlProxy";

export type Dept = {
  id: string;
  name: string;
};

export type Job = {
  id: string;
  name: string;
};

export type Role = {
  id: string;
  name: string;
  dataScope: string;
  level: number;
};

export type UserInfo = {
  avatarName: string;
  avatarPath: string;
  createTime: string;
  dept: Dept;
  email: string;
  enabled: boolean;
  gender: string;
  id: string | number;
  isAdmin: boolean;
  jobs: Array<Job>;
  nickName: string;
  password: string;
  pwdResetTime: string;
  roles: Array<Role>;
  updateBy: string;
  updateTime: string;
  username: string;
};

export type Authorities = {
  authority: string;
};

export type User = {
  authorities: Array<Authorities>;
  dataScopes: any;
  roles: string[];
  user: UserInfo;
};

export type UserResult = {
  // success: boolean;
  // data: {
  //   /** 用户名 */
  //   username: string;
  //   /** 当前登陆用户的角色 */
  //   roles: Array<string>;
  //   /** `token` */
  //   accessToken: string;
  //   /** 用于调用刷新`accessToken`的接口时所需的`token` */
  //   refreshToken: string;
  //   /** `accessToken`的过期时间（格式'xxxx/xx/xx xx:xx:xx'） */
  //   expires: Date;
  // };
  token: string;
  user: User;
};

export type RefreshTokenResult = {
  success: boolean;
  data: {
    /** `token` */
    accessToken: string;
    /** 用于调用刷新`accessToken`的接口时所需的`token` */
    refreshToken: string;
    /** `accessToken`的过期时间（格式'xxxx/xx/xx xx:xx:xx'） */
    expires: Date;
  };
};

/** 登录 */
export const getLogin = (data?: object) => {
  return http.request<UserResult>("post", baseUrlProxy + "/auth/login", {
    data
  });
};
export const getUerInfo = () => {
  return http.request<User>("get", baseUrlProxy + "/auth/info");
};

/** 刷新token */
// export const refreshTokenApi = (data?: object) => {
//   return http.request<RefreshTokenResult>("post", "/refresh-token", { data });
// };
export const getMenuData = () => {
  return http.request("get", baseUrlProxy + "/api/menus/build");
};
